package uk.ac.cam.cl.projectcharlie2010.game.player.physical;

import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;

import uk.ac.cam.cl.projectcharlie2010.clients.desktop.controller.CharlieProgramLogicException;

import ch.nostromo.tiffanys.game.move.MoveInput;

public class FakeVisualMoveRecogniser  implements VisualMoveRecogniser {

	private BufferedReader consoleReader;
	private boolean alive = true;

	public FakeVisualMoveRecogniser() {
		InputStreamReader isr = new InputStreamReader(System.in);
		consoleReader = new BufferedReader(isr);	
	}

	@Override
	public MoveInput seeNextMove() throws ImpossibleMoveException, AbortedException {
		try {
			System.out.println("Type 'from' string:");
			String from = consoleReader.readLine();
			if (!alive) throw new AbortedException();
			System.out.println("Type 'to' string:");
			String to = consoleReader.readLine();
			if (!alive) throw new AbortedException();
			return new MoveInput(from, to);
		} catch (IOException e) {
			throw new ImpossibleMoveException();
		}
	}

	@Override
	public void kill() {
		alive  = false;
	}

}
